package com.slz3.business.module.financeManagement.finReconciliationManage.domain;

import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.UsingFlag;
import com.slz3.business.frame.util.LocalDT;
import com.slz3.business.frame.util.UUIDUtils;
import com.slz3.business.frame.util.VE;
import org.springframework.util.MultiValueMap;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.stream.Collectors;

public class FinReconciliationManageFactory {

    /**
     * 初始化基础属性值
     */
    public static FinReconciliationManage initBaseFields(FinReconciliationManage finReconciliationManage) {
        if (finReconciliationManage.getUuid() == null) {
            finReconciliationManage.setUuid(UUIDUtils.generateUUID());
            finReconciliationManage.setCreateTime(LocalDateTime.now());
            if (VE.isEmpty(finReconciliationManage.getSerAudit())) {
                finReconciliationManage.setSerAudit(AuditFlag.WAIT_SUBMIT);
            }
            if (VE.isEmpty(finReconciliationManage.getSerUsing())) {
                finReconciliationManage.setSerUsing(UsingFlag.ENABLE);
            }
        } else {
            finReconciliationManage.setLastModifyTime(LocalDateTime.now());
        }
        return finReconciliationManage;
    }

    /**
     * 初始化基础属性值
     */
    public static FinReconciliationManage initBaseFields() {
        return initBaseFields(newTemStyle());
    }

    public static FinReconciliationManage newTemStyle() {
        return new FinReconciliationManage();
    }

    public static FinReconciliationManageCondition newFinReconciliationManageCondition(MultiValueMap<String, String> params) {

        FinReconciliationManageCondition condition = new FinReconciliationManageCondition();

        String createTimeOUTSET = params.getFirst("createTimeOUTSET");
        String createTimeFINISH = params.getFirst("createTimeFINISH");
        String lastModifyTimeOUTSET = params.getFirst("lastModifyTimeOUTSET");
        String lastModifyTimeFINISH = params.getFirst("lastModifyTimeFINISH");
        String serAuditList = params.getFirst("serAuditList");

        condition.setCreateTimeOUTSET(VE.isEmpty(createTimeOUTSET) ? null : LocalDT.parseStringToDateTime(createTimeOUTSET, FinReconciliationManageCondition.CREATE_TIME_OF_PATTERN));
        condition.setCreateTimeFINISH(VE.isEmpty(createTimeFINISH) ? null : LocalDT.parseStringToDateTime(createTimeFINISH, FinReconciliationManageCondition.CREATE_TIME_OF_PATTERN));
        condition.setLastModifyTimeOUTSET(VE.isEmpty(lastModifyTimeOUTSET) ? null : LocalDT.parseStringToDateTime(lastModifyTimeOUTSET, FinReconciliationManageCondition.CREATE_TIME_OF_PATTERN));
        condition.setLastModifyTimeFINISH(VE.isEmpty(lastModifyTimeFINISH) ? null : LocalDT.parseStringToDateTime(lastModifyTimeFINISH, FinReconciliationManageCondition.CREATE_TIME_OF_PATTERN));
        condition.setSerAuditList(VE.isEmpty(serAuditList) ? null : Arrays.stream(serAuditList.split(",")).map(item -> AuditFlag.valueOf(item)).collect(Collectors.toList()));

        return condition;

    }

}
